package com.ruoyi.activiti.listener;

import com.ruoyi.common.core.utils.SpringUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.finance.api.RemoteReciveReqService;
import com.ruoyi.system.api.domain.finance.ReciveReq;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

/**
 * @author wangenhao
 * @className ReciveReqListener
 * @description
 * @date 2024-11-10 下午10:14
 **/
@Slf4j
public class ReciveReqListener implements ExecutionListener {


    public void notify(DelegateExecution delegateExecution) {
        ReciveReq reciveReq = new ReciveReq();
        //设置财务应收单编号
        reciveReq.setOrderCode(delegateExecution.getProcessInstanceBusinessKey());

        Integer approvalResult = (Integer) delegateExecution.getVariable("approvalResult");
        String approvalOption = (String) delegateExecution.getVariable("approvalOption");
        //审核结果
        reciveReq.setApprovalResult(approvalResult);
        reciveReq.setApprovalOption(approvalOption);

        log.info("ReciveReqListener notify approvalResult:{}, approvalOption:{}", approvalResult, approvalOption);

        //调用远程接口修改财务应收单状态
        AjaxResult ajaxResult = SpringUtils.getBean(RemoteReciveReqService.class).updateReciveStatus(reciveReq);
        log.info("ReciveReqListener notify ajaxResult:{}", ajaxResult);
    }
}
